package models

import (
	"homes/homesrpc/homesrpc"

	"gorm.io/gorm"
)

type User struct {
	gorm.Model
	Account  string `gorm:"type:char(11);not null;"`
	Password string `gorm:"type:char(32);not null;"`
}

type House struct {
	gorm.Model
	Title  string  `gorm:"type:varchar(30);not null;"`
	Image  string  `gorm:"type:varchar(500);not null;"`
	Price  float64 `gorm:"type:decimal(10,2);not null;"`
	UserId int64   `gorm:"type:int(10);not null;"`
}

func (h *House) HouseList(db *gorm.DB, lists []*homesrpc.HouseList) ([]*homesrpc.HouseList, error) {
	err2 := db.Debug().Model(&House{}).
		Select("houses.*, houses.id AS house_id").
		Joins("LEFT JOIN users ON users.id = houses.user_id").
		Find(&lists).Error
	return lists, err2
}
